package com.meihua.shellapp.view;

import android.content.Context;
import android.text.InputType;
import android.widget.NumberPicker;
import android.widget.TextView;

import java.io.OptionalDataException;

/**
 * 作者：lc on 2017/10/16.
 * 邮箱：lc0607live@163.com
 */

public class MyNumberPicker extends NumberPicker {
    private int mMinValue;
    private int mValue;
    private int mMaxValue;
    private String[] mDisplayedValues;
    private TextView mInputText;
    private OptionalDataException mSelectorIndices;

    public MyNumberPicker(Context context) {
        super(context);
    }

    public void setMinValue(int minValue) {
        if (mMinValue == minValue) {
            return;
        }
        if (minValue < 0) {
            throw new IllegalArgumentException("minValue must be >= 0");
        }
        mMinValue = minValue;
        if (mMinValue > mValue) {
            mValue = mMinValue;
        }
        //boolean wrapSelectorWheel = mMaxValue - mMinValue > mSelectorIndices.length;
        //setWrapSelectorWheel(wrapSelectorWheel);
        //initializeSelectorWheelIndices();
        //updateInputTextView();
        //tryComputeMaxWidth();
        invalidate();
    }

    public void setMaxValue(int maxValue) {
        if (mMaxValue == maxValue) {
            return;
        }
        if (maxValue < 0) {
            throw new IllegalArgumentException("maxValue must be >= 0");
        }
        mMaxValue = maxValue;
        if (mMaxValue < mValue) {
            mValue = mMaxValue;
        }
        //boolean wrapSelectorWheel = mMaxValue - mMinValue > mSelectorIndices.length;
        //setWrapSelectorWheel(wrapSelectorWheel);
        //initializeSelectorWheelIndices();
        //updateInputTextView();
        //tryComputeMaxWidth();
        invalidate();
    }

    public void setDisplayedValues(String[] displayedValues) {
        if (mDisplayedValues == displayedValues) {
            return;
        }
        mDisplayedValues = displayedValues;
        if (mDisplayedValues != null) {
            // Allow text entry rather than strictly numeric entry.
            mInputText.setRawInputType(InputType.TYPE_CLASS_TEXT
                    | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
        } else {
            mInputText.setRawInputType(InputType.TYPE_CLASS_NUMBER);
        }
        boolean wrapSelectorWheel = mMaxValue - mMinValue > mSelectorIndices.length;
        setWrapSelectorWheel(wrapSelectorWheel);
//        updateInputTextView();
//        initializeSelectorWheelIndices();
//        tryComputeMaxWidth();
    }

}
